import {TESTADD, TODOSADD, SELECTALL, DELITEM, DELCOMPLETED, ALLSHOW, SHOWCHANGES, SETTODOS} from "./typeConst";

export const mutations = {
  [TESTADD]:(state)=>{
    state.test++
  },
  [TODOSADD]:(state,value)=>{
    state.todos.unshift(value);
  },
  [SELECTALL]:(state,value)=>{
    state.todos.forEach(item=>item.completed = value);
  },
  [DELITEM]:(state,value)=>{
    state.todos.splice(value,1);
  },
  [DELCOMPLETED]:state=>{
    state.todos = state.todos.filter(item=>item.completed === false);
  },
  [ALLSHOW]: state=>{
    state.todos.forEach(item=>{item.show = true});
  },
  [SHOWCHANGES]: (state,value)=>{
    state.todos.forEach(item=>{
      if(item.completed === value){
        item.show = true;
      }else{
        item.show = false;
      }
    })
  },
  [SETTODOS]:(state,value)=>{
    state.todos = value;
  }
}
